﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text.RegularExpressions;

namespace BackupMirthToTFS
{
    public static class StringExtension
    {
        public static string GenerateSlug(this string phrase)
        {
            string str = phrase.ToLower();

            str = Regex.Replace(str, @"[^a-z0-9\s-]", ""); // invalid chars           
            str = Regex.Replace(str, @"\s+", " ").Trim(); // convert multiple spaces into one space   
            str = str.Substring(0, str.Length <= 45 ? str.Length : 45).Trim(); // cut and trim it   
            str = Regex.Replace(str, @"\s", "-"); // hyphens   

            return str;
        }

        public static string FormatWith(this string format, params object[] args)
        {
            if (format == null) { throw new ArgumentNullException("format"); }

            return string.Format(format, args);
        }

        public static bool HasValue(this string input)
        {
            return (!string.IsNullOrEmpty(input));
        }
    }
}